package com.Service.Impl;

import com.Service.ShuihuService;
import com.entity.Shuihu;
import com.mapper.DaoImpl.ShuihuMapperImpl;
import com.mapper.ShuihuMapper;
import com.qo.PageResult;
import com.qo.QueryObject;

import java.util.List;

public class ShuihuServiceImpl implements ShuihuService {
    private ShuihuMapper shuihuDao = new ShuihuMapperImpl();

    @Override
    public void save(Shuihu shuihu) {
        //根据传递的参数获取id属性值 -- 根据用户是否在请求地址中传递id属性时
        if (shuihu.getId() == null) {
            //调用添加
            shuihuDao.add(shuihu);
        } else {
            //将获取到的id属性值设置给当前对象
            //调用修改
            shuihuDao.edit(shuihu);

        }
    }

    @Override
    public void delById(Long id) {
        shuihuDao.delById(id);
    }

    @Override
    public Shuihu selOneById(Long id) {
        return shuihuDao.selOneById(id);
    }

    @Override
    public List<Shuihu> selAll() {
        return shuihuDao.selAll();
    }

    @Override
    public PageResult<Shuihu> query(QueryObject qo) {
        //当返回一个PageResult<Shuihu>对象,要七个参数
        Integer totalCount = shuihuDao.selCount(qo);
        if (totalCount == 0) {
            return new PageResult<>();
        }
        List<Shuihu> data = shuihuDao.selList(qo);
        return new PageResult<>(qo.getCurrentPage(), qo.getPageSize(), totalCount, data);
    }
}
